/*
 * InformaRecebimentoAction.java
 *
 * Created on August 7, 2007, 10:44 AM
 */

package br.usp.poli.mfc.struts.action;

import br.usp.poli.mfc.struts.DAO.DAOFactory;
import br.usp.poli.mfc.struts.DAO.ListaDAO;
import br.usp.poli.mfc.struts.DAO.RevistaDAO;
import br.usp.poli.mfc.struts.actionform.DoInscricaoActionForm;
import br.usp.poli.mfc.struts.bean.Lista;
import br.usp.poli.mfc.struts.bean.Usuario;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
/**
 *
 * @author William T.
 * @version
 */

public class InformaRecebimentoAction extends Action {
    
    private final static String NEXT = "next";
    
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        HttpSession session = request.getSession();
        Usuario user = (Usuario)session.getAttribute("usuario");
        ActionMessages messages = new ActionMessages();
        RevistaDAO revistaDAO = DAOFactory.getRevistaDAO();
        ListaDAO listaDAO = DAOFactory.getListaDAO();
        DoInscricaoActionForm frm = (DoInscricaoActionForm)form;
        Lista lista = listaDAO.getListaByRevistaUsuario(frm.getIdRevista(),user.getId_usuario());
        Date d = new Date();
        lista.setDt_Recebimento(d);
        if(listaDAO.updateLista(lista)) {
            messages.add("log",new ActionMessage("informarecebimento.ok"));
            saveErrors(request,messages);
        } else {
            messages.add("log",new ActionMessage("informarecebimento.nok"));
            saveErrors(request,messages);
        }
        return mapping.findForward(NEXT);
    }
}
